package com.payment.ktb.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.payment.ktb.R;
import com.payment.ktb.application.MyApplication;
import com.payment.ktb.model.PaymentOrder;

import java.util.List;

/**
 * Created by syd on 2016/6/20.
 */
public class PaymentOrderRecordAdapter extends BaseAdapter {


    private Context context;
    private List<PaymentOrder> listdata;


    public PaymentOrderRecordAdapter(Context context, List<PaymentOrder> listdata) {
        this.context = context;
        this.listdata = listdata;
    }

    public PaymentOrderRecordAdapter() {
    }




    @Override
    public int getCount() {
        return listdata.size();
    }

    @Override
    public Object getItem(int position) {
        return listdata.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_orderrecord_item, null);
            viewHolder.tv_orderrecord_orderType = (TextView) convertView.findViewById(R.id.tv_orderrecord_orderType);
            viewHolder.tv_orderrecord_amount = (TextView) convertView.findViewById(R.id.tv_orderrecord_amount);
            viewHolder.tv_orderrecord_orderReqTime = (TextView) convertView.findViewById(R.id.tv_orderrecord_orderReqTime);
            viewHolder.tv_orderrecord_orderStatusName = (TextView) convertView.findViewById(R.id.tv_orderrecord_orderStatusName);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.tv_orderrecord_orderType.setText(listdata.get(position).getOrderType());
        viewHolder.tv_orderrecord_amount.setText(listdata.get(position).getAmount());
        viewHolder.tv_orderrecord_orderReqTime.setText(listdata.get(position).getOrderReqTime());
        viewHolder.tv_orderrecord_orderStatusName.setText(listdata.get(position).getOrderStatusName());
        if (listdata.get(position).getOrderStatus() == 20) {
            viewHolder.tv_orderrecord_orderStatusName.setTextColor(MyApplication.getContext().getResources().getColor(R.color.green));
        } else if (listdata.get(position).getOrderStatus() == 21) {
            viewHolder.tv_orderrecord_orderStatusName.setTextColor(MyApplication.getContext().getResources().getColor(R.color.red));
        } else {
            viewHolder.tv_orderrecord_orderStatusName.setTextColor(MyApplication.getContext().getResources().getColor(R.color.text464646));

        }

        return convertView;
    }



    /**
     *
     */
    class ViewHolder {
        TextView tv_orderrecord_orderType;
        TextView tv_orderrecord_amount;
        TextView tv_orderrecord_orderReqTime;
        TextView tv_orderrecord_orderStatusName;
    }


}
